package com.quicks.beauty.server.web;

import com.quicks.beauty.core.entity.BeautyCompany;
import com.quicks.beauty.core.vo.ComExchangeVO;
import com.quicks.beauty.server.common.AjaxResult;
import com.quicks.beauty.server.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "company")
@Api(tags = "公司介绍")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 公司详情
     *
     * @return
     */
    @RequestMapping(value = "first", method = RequestMethod.GET)
    @ApiOperation(value = "公司详情")
    public AjaxResult getCompanyInfo() {
        AjaxResult success = AjaxResult.success();
        try {
            BeautyCompany company = companyService.getFirstCompany();
            ArrayList<String> list = new ArrayList<>();
            list.add(company.getId());
            list.add(company.getName());
            list.add(company.getDescription());
            success.setData(list);
        } catch (Exception e) {
            success.setSuccess(false);
            success.setMsg("服务器打盹中...");
            e.printStackTrace();
        }
        return success;
    }

     /**
     * 公司详情
     *
     * @return
     */
    @RequestMapping(value = "latest", method = RequestMethod.GET)
    @ApiOperation(value = "公司详情")
    public AjaxResult getCompanyInfo2() {
        AjaxResult success = AjaxResult.success();
        try {
            List<ComExchangeVO> companys  = companyService.getLatestExchange();
            ComExchangeVO company = companys.get(0);
            ArrayList<Object> list = new ArrayList<>();
            list.add(company.getExchange());
            list.add(company.getCompanyName());
            list.add(company.getDescription());
            success.setData(list);
        } catch (Exception e) {
            success.setSuccess(false);
            success.setMsg("服务器打盹中...");
            e.printStackTrace();
        }
        return success;
    }




}
